package com.qf.day31_boot.exhandler;

import com.qf.day31_boot.vo.vo.ResultVo;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice // 全局异常处理器类，返回的是json数据
public class GlobalExHandler {

    @ExceptionHandler(ParamNullException.class)
    public ResultVo handleParamNullEx(ParamNullException e) {

        final Integer code = e.getCode();
        final String msg = e.getMsg();

        return ResultVo.fail(msg);

    }

    @ExceptionHandler(Exception.class) // 需要处理的异常类型是什么
    public ResultVo handleEx(Exception e) {
        return ResultVo.fail(e.getMessage());
    }

}
